

#if !defined(QMITK_KillBone_H__INCLUDED)
#define QMITK_KillBone_H__INCLUDED

#ifdef WIN32
#pragma warning( disable : 4250 )
#endif

#include "QmitkFunctionality.h"
#include <mitkCuboid.h>
#include <mitkOperationActor.h>
#include <mitkOperation.h>
#include <mitkAffineInteractor.h>
#include "mitkWeakPointer.h"
#include <itkImage.h>
#include <QProgressDialog>

#include "WxVolumeRenderingPicker.h"

#include <QmitkStdMultiWidget.h>
#include <vtkRenderWindow.h>

#include "ui_QmitkKillBoneControls.h"

#include "QmitkDataPositioning.h" //
/*!
\ingroup org_mitk_gui_qt_KillBone_internal
\brief Functionality for cropping images with a cuboid

This functionality lets the user select an image from the data tree, select an area of interest by placing
a cuboid object, and then crop the image, so that pixels from outside the cuboid will remove.

The image size is automatically reduced, if the cuboid is not rotated but parallel to the image axes.

\b Implementation

The functionality owns a cuboid (m_CroppingObject) and the associated interactor (m_AffineInteractor),
which implements moving and scaling the cuboid.

*/


class QmitkKillBone : public QObject, public QmitkFunctionality, public mitk::OperationActor
{



  /// Operation base class, which holds pointers to a node of the data tree (mitk::DataNode)
  /// and to two data sets (mitk::BaseData) instances
  class opExchangeNodes: public mitk::Operation
  {
  public: opExchangeNodes( mitk::OperationType type,  mitk::DataNode* node,
            mitk::BaseData* oldData,
            mitk::BaseData* newData );
          ~opExchangeNodes();
          mitk::DataNode* GetNode() { return m_Node; }
          mitk::BaseData* GetOldData() { return m_OldData; }
          mitk::BaseData* GetNewData() { return m_NewData; }
  protected:
    void NodeDeleted(const itk::Object * /*caller*/, const itk::EventObject & /*event*/);
  private:
    mitk::DataNode* m_Node;
    mitk::BaseData::Pointer m_OldData;
    mitk::BaseData::Pointer m_NewData;
    long m_NodeDeletedObserverTag;
    long m_OldDataDeletedObserverTag;
    long m_NewDataDeletedObserverTag;
  };

private:

  Q_OBJECT

public:
  /*!
  \brief Constructor. Called by SampleApp (or other apps that use functionalities)
  */
  QmitkKillBone(QObject *parent=0);

  /*!
  \brief Destructor
  */
  virtual ~QmitkKillBone();

  /*!
  \brief Creates the Qt widget containing the functionality controls, like sliders, buttons etc.
  */
  virtual void CreateQtPartControl(QWidget* parent);

  /*!
  \brief Creates the Qt connections needed
  */
  virtual void CreateConnections();

  /*!
  \brief Invoked when this functionality is selected by the application
  */
  virtual void Activated();

  /*!
  \brief Invoked when the user leaves this functionality
  */
  virtual void Deactivated();

  ///
  /// Called when a StdMultiWidget is available.
  ///
  virtual void StdMultiWidgetAvailable(QmitkStdMultiWidget& stdMultiWidget);
  ///
  /// Called when no StdMultiWidget is available.
  ///
  virtual void StdMultiWidgetNotAvailable();


  /*
  \brief Interface of a mitk::StateMachine (for undo/redo)
  */
  virtual void  ExecuteOperation (mitk::Operation*);

  QWidget* GetControls();

  const mitk::DataNode::Pointer selectedImage();

  public slots:


    virtual void KillBone();

    virtual void OnImageSelectionChanged(const mitk::DataNode* /*node*/);
    virtual void OnStopOpacityChanged(int v);
protected:

  /*!
  * Default main widget containing 4 windows showing 3
  * orthogonal slices of the volume and a 3d render window
  */
  QmitkStdMultiWidget* m_MultiWidget;

  /*!
  * Controls containing an image selection drop down, some usage information and a "crop" button
  */
  Ui::QmitkKillBoneControls * m_Controls;

  /*!
  * \brief A pointer to the node of the image to be croped.
  */
  mitk::WeakPointer<mitk::DataNode> m_ImageNode;

  /*!
  * \brief A pointer to the image to be cropped.
  */
  mitk::WeakPointer<mitk::Image> m_ImageToCrop;


  virtual void NodeRemoved(const mitk::DataNode* node);


  mitk::WxVolumeRenderingPicker::Pointer m_Picker;

private:

  // operation constant
  static const mitk::OperationType OP_EXCHANGE;

  QProgressDialog *progress;
  mitk::Image::Pointer m_surrImage;
  template < typename TPixel, unsigned int VImageDimension >
  void ItkImageProcessing( itk::Image< TPixel, VImageDimension >* itkImage, mitk::Geometry3D* imageGeometry, mitk::DataNode* parent );

};
#endif // !defined(QMITK_KillBone_H__INCLUDED)
